<template>
  <div class="video-box" :class="type">
    <div class="rtmp" v-if="!isShowUserTrtc"></div>
    <div v-else>
      <!-- 底部的控制按钮 -->
      <div class="control">
        <img src="@/assets/img/trtc/icon-mic.png" class="link" v-if="isMaster" alt="" />
        <img src="@/assets/img/trtc/icon-speake.png" class="link" v-else alt="" />
        <div class="name">姓名</div>
        <!-- 麦克风开启时的图标 -->
        <!-- <img src="@/assets/img/trtc/icon-mute(1).png" class="audio" alt="" /> -->
        <!-- 麦克风关闭时的图标 -->
        <img src="@/assets/img/trtc/icon-dismute-uneditable.png" class="audio" alt="" />
      </div>
      <!-- 无视频的背景显示 -->
      <div class="none" v-if="!userInfo.video">
        <img src="@/assets/img/trtc/default-headshot-video.svg" alt="" />
      </div>
    </div>
  </div>
</template>

<script>
export default {
  props: {
    type: {
      type: String,
      default: "",
    },
    userInfo: {
      type: Object,
      default: {},
    },
    masterUserId: {
      type: String,
      default: "",
    },
    isMaster: {
      type: Boolean,
      default: false,
    },
    isShowUserTrtc: {
      type: Boolean,
      default: false,
    },
  },
  data() {
    return {};
  },
  computed: {},
  mounted() {
    console.log("输出视频窗口的用户信息", this.userInfo);
  },
  methods: {
    setIMFn(data) {
      this.$store.dispatch("setIMFn", {
        name: "createCustomMessage",
        data: {
          data: data,
        },
      });
    },
    closeAudio() {
      // 需要调用IM自定义消息,关闭某人的麦克风
      let data = {
        data: {
          userId: this.userInfo.userId,
          has: "-1",
        },
        description: "audio",
        extension: "TRTCControl",
      };
      data.data = JSON.stringify(data.data);
      this.setIMFn(data);
    },
    openAudio() {
      // 需要调用IM自定义消息,开启某人的麦克风
      let data = {
        data: {
          userId: this.userInfo.userId,
          has: "1",
        },
        description: "audio",
        extension: "TRTCControl",
      };
      data.data = JSON.stringify(data.data);
      this.setIMFn(data);
    },
    closeVideo() {
      // 需要调用IM自定义消息,关闭某人的摄像头
      let data = {
        data: {
          userId: this.userInfo.userId,
          has: "-1",
        },
        description: "video",
        extension: "TRTCControl",
      };
      data.data = JSON.stringify(data.data);
      this.setIMFn(data);
    },
    openVideo() {
      // 需要调用IM自定义消息,开启某人的摄像头
      let data = {
        data: {
          userId: this.userInfo.userId,
          has: "1",
        },
        description: "video",
        extension: "TRTCControl",
      };
      data.data = JSON.stringify(data.data);
      this.setIMFn(data);
    },
  },
};
</script>

<style lang="scss">
.video-box {
  //   border: solid 0.5px #666666;
  position: relative;
  display: none;
  .none {
    width: 100%;
    height: 100%;
    background: #3b4144;
    display: flex;
    align-items: center;
    justify-content: center;
    img {
      width: 50px;
      height: 50px;
    }
  }
  .control {
    position: absolute;
    bottom: 0;
    left: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    height: 20px;
    padding-right: 6px;
    background: #000000;
    opacity: 0.5;
    .link {
      height: 100%;
      width: 20px;
    }
    .name {
      font-size: 13px;
      font-weight: 400;
      color: #ffffff;
      line-height: 13px;
      margin: 0 6px;
    }
    .audio {
      width: 8px;
      height: 11px;
    }
  }
  &.max {
    display: block;
    width: 100%;
    height: 22vh;

    .none {
      img {
        width: 80px;
        height: 80px;
      }
    }
  }
  &.min {
    display: block;
    width: 8.5vw;
    height: 11.33vh;
  }
}
</style>
